package eleanor.ltd.isne.entities.user.group;

import java.io.Serializable;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.NonVisual;

import eleanor.ltd.isne.entities.roles.group.RolesGroup;
import eleanor.ltd.isne.entities.user.User;

@Entity
@Table(name = "usergroup")
@AssociationOverrides({
	@AssociationOverride(name = "ugpk.rolesGroup.roles", joinColumns = @JoinColumn(name = "rolesGroup_roles_id")),
	@AssociationOverride(name = "ugpk.rolesGroup.pagesAction", joinColumns = @JoinColumn(name = "rolesGroup_pagesAction_id")),
	@AssociationOverride(name = "ugpk.user", joinColumns = @JoinColumn(name = "user_id")) })
public class UserGroup implements Serializable {
	
	@EmbeddedId
	private UserGroupPK ugpk = new UserGroupPK();
	
	public UserGroupPK getUgpk() {
		return ugpk;
	}
	public void setUgpk(UserGroupPK ugpk) {
		this.ugpk = ugpk;
	}
	
	public void setRolesGroup(RolesGroup rolesGroup) {
		ugpk.setRolesGroup(rolesGroup);
	}
	
	@Transient
	public RolesGroup getRolesGroup() {
		return ugpk.getRolesGroup();
	}
	
	public void setUser(User user) {
		ugpk.setUser(user);
	}
	
	@Transient
	public User getUser() {
		return ugpk.getUser();
	}
	
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		UserGroup that = (UserGroup) o;

		if (getUgpk() != null ? !getUgpk().equals(that.getUgpk()) : that.getUgpk() != null)
			return false;

		return true;
	}
	
}
